package com.yc;

import java.lang.reflect.Field;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args ) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException, InstantiationException {
        Class aClass = Class.forName("com.yc.A");

        A a = new A();

        Class bClass = B.class;

        B b = new B();

        //获取公开的字段public
        Field[] fields = aClass.getFields();

        for (Field field : fields) {
            System.out.println(field);
        }


        Field length = aClass.getDeclaredField("length");
        //设置强制访问
        length.setAccessible(true);
        length.set(a,10);

        System.out.println(a.getLength());


        Field[] declaredFields = bClass.getDeclaredFields();
        System.out.println("B的属性个数：" + declaredFields.length);



    }
}


class A{
    private int length;
    public int width;
    protected int height;

    public int getLength() {
        return length;
    }

    public int getWidth() {
        return width;
    }

    public int getHeight() {
        return height;
    }
}

class B extends A{
    private String size;

    public String getSize() {
        return size;
    }
}
